package com.chixing.controller;

import com.chixing.util.UploadImgUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("qiniu")
public class QiniuCloudUploadController {

    @RequestMapping("upload")
    @ResponseBody
        public Map upload(MultipartFile myfile) {
            Map map = new HashMap<>();

            try {
                String imgUrl = UploadImgUtil.upload(myfile.getBytes(),myfile.getOriginalFilename());
                System.out.println("该图片在七牛云的URL:" + imgUrl);
                map.put("imgUrl", imgUrl);
            } catch (IOException e) {
                e.printStackTrace();
                map.put("imgUrl", null);
            }
            return map;
        }

}
